export default function saveProgram (data, type) {
  let configData = {
    PrepareTime: '',
    RunTime: '',
    RestTime: '',
    Repetitions: '',
    ProgramName: '',
    ProgramMinutes: ''
  }
  data.sport.forEach(item => {
    switch (item.name) {
      case '准备':
        configData.PrepareTime = Number(item.value)
        break
      case '运动':
        configData.RunTime = Number(item.value)
        break
      case '休息':
        configData.RestTime = Number(item.value)
        break
      case '次数':
        configData.Repetitions = Number(item.value)
        break
      case '项目':
        configData.ProgramName = item.value
        break
    }
  })
  configData.ProgramMinutes = Number(data.totleTime.split(' ')[0])
  wx.cloud.callFunction({
    // 要调用的云函数名称
    name: 'program',
    // 传递给云函数的参数
    data: {
      type,
      ...configData
    },
    success: res => res,
    fail: err => err
  })
}
